package Offer_09;

import java.util.ArrayDeque;
import java.util.Deque;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2023/3/28 11:13
 */
public class Solution {
    class CQueue {
        public Deque<Integer> inStack;
        public Deque<Integer> outStack;
        public CQueue() {
            inStack = new ArrayDeque<Integer>();
            outStack = new ArrayDeque<Integer>();
        }

        public void appendTail(int value) {
            inStack.push(value);
        }

        public int deleteHead() {
            if (inStack.isEmpty() && outStack.isEmpty()){
                return -1;
            }
            if (!outStack.isEmpty()){
                return outStack.pop();
            }
            while (!inStack.isEmpty()){
                outStack.push(inStack.pop());
            }
            return outStack.pop();
        }
    }
    //-------------------------------------------------------Most Fast
    class CQueue1 {
        public Deque<Integer> inStack;
        public Deque<Integer> outStack;
        public CQueue1() {
            inStack = new ArrayDeque<Integer>();
            outStack = new ArrayDeque<Integer>();
        }

        public void appendTail(int value) {
            inStack.push(value);
        }

        public int deleteHead() {
            if (outStack.isEmpty()){
                if (inStack.isEmpty() ){
                    return -1;
                }
                method();
            }
            return outStack.pop();
        }
        private void  method (){
            while (!inStack.isEmpty()){
                outStack.push(inStack.pop());
            }
        }
    }
}
